﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Data.SqlTypes;
using System.ComponentModel;
using System.Data.SqlClient;

namespace TradingAppDal
{
    public class SecurityDal : DataAccess
    {
        public SqlInt64 Entity_ID { get; set; }
        public SqlInt64 SecOrder_ID { get; set; }
        public string Entity_Name { get; set; }
        public string Security_Name { get; set; }
        public bool IsError { get; set; }
        public string ErrorMessage { get; set; }
        public SqlDateTime SecGroup_FromDate { get; set; }
        public SqlDateTime SecGroup_ToDate { get; set; }
        public SqlDateTime SecGroup_MaxDate { get; set; }
        public SqlDateTime SecGroup_Requested { get; set; }
        public SqlDateTime SecGroup_InQue { get; set; }
        public SqlDateTime SecGroup_InProcess { get; set; }
        public SqlDateTime SecGroup_Processed { get; set; }
        public string ReportingName
        {
            get
            {
                //return Security_Name + " (" + SecOrder_ID.ToString() + ")";
                return Security_Name;
            }
        }
        public string SecGroup_InQueStr
        {
            get
            {
                return TradingAppUtil.GetDateString(SecGroup_InQue);
            }
        }
        public string SecGroup_InProcessStr
        {
            get
            {
                return TradingAppUtil.GetDateString(SecGroup_InProcess);
            }
        }
        public string SecGroup_ProcessedStr
        {
            get
            {
                return TradingAppUtil.GetDateString(SecGroup_Processed);
            }
        }
        public bool IsProcessingCompleted { get; set; }
        public SqlInt64 Process_ID { get; set; }
        public EntityDal ParentEntity { get; set; }
        public List<SecurityDal> GetSecurities(SqlInt64 ProcessID, EntityType oEntityType)
        {
            List<SecurityDal> lst = new List<SecurityDal>();
            try
            {
                Dictionary<long, EntityDal> DictEntities = new Dictionary<long, EntityDal>();
                EntityDal oEntityDal = new EntityDal();
                string sp_Name = GetFetchSPName(oEntityType);
                SqlCommand cmd = GetSPCommand(sp_Name);
                cmd.Parameters.Add(new SqlParameter("@Process_ID", ProcessID));
                SqlDataReader reader = cmd.ExecuteReader();
                while (reader.Read())
                {
                    SecurityDal oSecurityDal = new SecurityDal();
                    oSecurityDal.Process_ID = ToSqlInt64(reader["Process_ID"]);
                    oSecurityDal.Security_Name = ToString(reader["Sec_Client_ID"]);
                    oSecurityDal.SecOrder_ID = ToSqlInt64(reader["SecOrder_ID"]);

                    //oSecurityDal.SecGroup_FromDate = ToSqlDateTime(reader["SecGroup_FromDate"]);
                    //oSecurityDal.SecGroup_ToDate = ToSqlDateTime(reader["SecGroup_ToDate"]);
                    //oSecurityDal.SecGroup_MaxDate = ToSqlDateTime(reader["SecGroup_MaxDate"]);
                    oSecurityDal.SecGroup_Requested = ToSqlDateTime(reader["SecGroup_Requested"]);
                    oSecurityDal.SecGroup_InQue = ToSqlDateTime(reader["SecGroup_InQue"]);
                    oSecurityDal.SecGroup_InProcess = ToSqlDateTime(reader["SecGroup_InProcess"]);
                    oSecurityDal.SecGroup_Processed = ToSqlDateTime(reader["SecGroup_Processed"]);
                    if (oEntityType == EntityType.Processed)
                    {
                        oSecurityDal.IsProcessingCompleted = true;
                    }
                    if (oEntityType == EntityType.InQueue || oEntityType == EntityType.InProcess)
                    {
                        oSecurityDal.ParentEntity = GetParentEntity(oSecurityDal.Process_ID.Value, DictEntities);
                    }
                    lst.Add(oSecurityDal);
                }
                reader.Close();
                reader = null;

            }
            finally
            {
                CloseConnection();
            }

            return lst;
        }
        private EntityDal GetParentEntity(long Process_ID, Dictionary<long, EntityDal> DictEntities)
        {
            EntityDal oEntityDal = new EntityDal();
            EntityDal oParentEntity;
            if (DictEntities.ContainsKey(Process_ID))
            {
                oParentEntity = DictEntities[Process_ID];
            }
            else
            {
                oParentEntity = oEntityDal.GetEntityByProcessID(Process_ID);
                DictEntities.Add(Process_ID, oParentEntity);
            }
            return oParentEntity;
        }
        public List<SecurityDal> GetEntitySecurities(SqlInt64 ProcessID, EntityType oEntityType)
        {
            List<SecurityDal> lst = new List<SecurityDal>();
            try
            {
                string sp_Name = GetFetchSPName(oEntityType);
                SqlCommand cmd = GetSPCommand(sp_Name);
                cmd.Parameters.Add(new SqlParameter("@Process_ID", ProcessID));
                SqlDataReader reader = cmd.ExecuteReader();
                while (reader.Read())
                {
                    SecurityDal oSecurityDal = new SecurityDal();
                    oSecurityDal.Process_ID = ToSqlInt64(reader["Process_ID"]);
                    oSecurityDal.Security_Name = ToString(reader["Sec_Client_ID"]);
                    oSecurityDal.SecOrder_ID = ToSqlInt64(reader["SecOrder_ID"]);

                    //oSecurityDal.SecGroup_FromDate = ToSqlDateTime(reader["SecGroup_FromDate"]);
                    //oSecurityDal.SecGroup_ToDate = ToSqlDateTime(reader["SecGroup_ToDate"]);
                    //oSecurityDal.SecGroup_MaxDate = ToSqlDateTime(reader["SecGroup_MaxDate"]);
                    oSecurityDal.SecGroup_Requested = ToSqlDateTime(reader["SecGroup_Requested"]);
                    oSecurityDal.SecGroup_InQue = ToSqlDateTime(reader["SecGroup_InQue"]);
                    oSecurityDal.SecGroup_InProcess = ToSqlDateTime(reader["SecGroup_InProcess"]);
                    oSecurityDal.SecGroup_Processed = ToSqlDateTime(reader["SecGroup_Processed"]);

                    lst.Add(oSecurityDal);
                }
                reader.Close();
                reader = null;

            }
            finally
            {
                CloseConnection();
            }

            return lst;
        }
        public SqlInt32 UpdateSecurity(long SecOrder_ID, EntityType oEntityType)
        {
            SqlInt32 iError = 0;
            string update_SP_Name = GetUpdateSPName(oEntityType);
            SqlCommand cmd = GetSPCommand(update_SP_Name);

            try
            {
                cmd.Parameters.Add(new SqlParameter("@SecOrder_ID", SecOrder_ID));
                cmd.ExecuteNonQuery();

            }
            finally
            {
                CloseConnection(cmd.Connection);
            }

            return iError;
        }

        private string GetUpdateSPName(EntityType oEntityType)
        {
            string sp_Name = "";
            switch (oEntityType)
            {
                case EntityType.InQueue:
                    sp_Name = "sp_Update_Securities_InQue ";
                    break;
                case EntityType.InProcess:
                    sp_Name = "sp_Update_Securities_InProcess ";
                    break;
                case EntityType.Processed:
                    sp_Name = "sp_Update_Securities_Processed";
                    break;
            }
            return sp_Name;
        }

        private string GetFetchSPName(EntityType oEntityType)
        {
            string sp_Name = "";
            switch (oEntityType)
            {
                case EntityType.InQueue:
                    sp_Name = "get_Securities_InQueue";
                    break;
                case EntityType.InProcess:
                    sp_Name = "get_Securities_InProcess";
                    break;
                case EntityType.Processed:
                    sp_Name = "get_Securities_Processed";
                    break;
                case EntityType.ToProcess:
                    sp_Name = "get_Securities_ToProcess";
                    break;
                case EntityType.All:
                    sp_Name = "get_Securities_All";
                    break;
            }
            return sp_Name;
        }
        public List<CorpActionsDal> GetSecurityCorpActions(SqlInt64 SecOrder_ID)
        {
            List<CorpActionsDal> lst = new List<CorpActionsDal>();
            SqlCommand cmd = GetSPCommand("get_Securities_CorpActions");
            try
            {
                cmd.Parameters.Add(new SqlParameter("@SecOrder_ID", SecOrder_ID));
                SqlDataReader reader = cmd.ExecuteReader();
                while (reader.Read())
                {
                    CorpActionsDal oCorpActionsDal = new CorpActionsDal();
                    oCorpActionsDal.SecOrder_ID = ToInt64(reader["SecOrder_ID"]);
                    oCorpActionsDal.Process_ID = ToInt64(reader["Process_ID"]);
                    oCorpActionsDal.Portifolio_Client_ID = ToString(reader["Portifolio_Client_ID"]);
                    oCorpActionsDal.CorpAction_Sec_Client_ID = ToString(reader["CorpAction_Sec_Client_ID"]);
                    oCorpActionsDal.CorpAction_Date = ToDateTime(reader["CorpAction_Date"]);
                    oCorpActionsDal.CorpAction_Type_ID = ToInt32(reader["CorpAction_Type_ID"]);
                    oCorpActionsDal.CorpAction_RecievedShares = ToDecimal(reader["CorpAction_RecievedShares"]);
                    oCorpActionsDal.CorpAction_DeliveredShares = ToDecimal(reader["CorpAction_DeliveredShares"]);
                    oCorpActionsDal.CorpAct_New_Sec_Client_ID = ToString(reader["CorpAct_New_Sec_Client_ID"]);
                    lst.Add(oCorpActionsDal);
                }
                reader.Close();
                reader = null;
            }
            finally
            {
                CloseConnection(cmd.Connection);
            }

            return lst;
        }
        public List<DividentsDal> GetSecurityDividents(SqlInt64 SecOrder_ID)
        {
            List<DividentsDal> lst = new List<DividentsDal>();
            SqlCommand cmd = GetSPCommand("get_Securities_Dividends");
            try
            {
                cmd.Parameters.Add(new SqlParameter("@SecOrder_ID", SecOrder_ID));
                SqlDataReader reader = cmd.ExecuteReader();
                while (reader.Read())
                {
                    DividentsDal odiv = new DividentsDal();
                    odiv.SecOrder_ID = ToInt64(reader["SecOrder_ID"]);
                    odiv.Process_ID = ToInt64(reader["Process_ID"]);
                    odiv.Portfolio_Client_ID = ToString(reader["Portfolio_Client_ID"]);
                    odiv.Sec_Client_ID = ToString(reader["Sec_Client_ID"]);
                    odiv.Div_Client_Dividend_ID = ToString(reader["Div_Client_Dividend_ID"]);
                    odiv.Div_Client_Dividend_Code = ToString(reader["Div_Client_Dividend_Code"]);
                    odiv.Div_Client_LongShort = ToString(reader["Div_Client_LongShort"]);
                    odiv.Div_Dividend_Gross_Local = ToDecimal(reader["Div_Dividend_Gross_Local"]);
                    odiv.Div_Dividend_Gross = ToDecimal(reader["Div_Dividend_Gross"]);
                    odiv.Div_Dividend_Rate = ToDateTime(reader["Div_Dividend_Rate"]);
                    odiv.Div_TaxWithheld_Gross_Local = ToDateTime(reader["Div_TaxWithheld_Gross_Local"]);
                    odiv.Div_TaxWithheld_Gross = ToDateTime(reader["Div_TaxWithheld_Gross"]);
                    lst.Add(odiv);
                }
                reader.Close();
                reader = null;
            }
            finally
            {
                CloseConnection(cmd.Connection);
            }

            return lst;
        }
        public List<IdentifiedStraddlesDal> GetSecurityIdentifiedStraddles(SqlInt64 SecOrder_ID)
        {
            List<IdentifiedStraddlesDal> lst = new List<IdentifiedStraddlesDal>();
            SqlCommand cmd = GetSPCommand("get_Securities_IdentifiedStraddles");
            try
            {
                cmd.Parameters.Add(new SqlParameter("@SecOrder_ID", SecOrder_ID));
                SqlDataReader reader = cmd.ExecuteReader();
                while (reader.Read())
                {
                    IdentifiedStraddlesDal ostrad = new IdentifiedStraddlesDal();
                    ostrad.SecOrder_ID = ToInt64(reader["SecOrder_ID"]);
                    ostrad.Process_ID = ToInt64(reader["Process_ID"]);
                    ostrad.Portfolio_Client_ID = ToString(reader["Portfolio_Client_ID"]);
                    ostrad.Sec_Client_ID = ToString(reader["Sec_Client_ID"]);
                    ostrad.Tran_Client_Open_ID = ToString(reader["Tran_Client_Open_ID"]);
                    ostrad.Tran_Client_Close_ID = ToString(reader["Tran_Client_Close_ID"]);
                    ostrad.Portfolio_Client_ID_Offset = ToString(reader["Portfolio_Client_ID_Offset"]);
                    ostrad.Sec_Client_ID_Offset = ToString(reader["Sec_Client_ID_Offset"]);
                    ostrad.Tran_Client_Open_ID_Offset = ToString(reader["Tran_Client_Open_ID_Offset"]);
                    ostrad.Tran_Client_Close_ID_Offset = ToString(reader["Tran_Client_Close_ID_Offset"]);
                    ostrad.IdentifiedStraddle_unique_ID = ToString(reader["IdentifiedStraddle_unique_ID"]);
                    lst.Add(ostrad);
                }
                reader.Close();
                reader = null;
            }
            finally
            {
                CloseConnection(cmd.Connection);
            }

            return lst;
        }
        public List<M1Dal> GetSecurityM1Dal(SqlInt64 SecOrder_ID)
        {
            List<M1Dal> lst = new List<M1Dal>();
            SqlCommand cmd = GetSPCommand("get_Securities_M1s");
            try
            {
                cmd.Parameters.Add(new SqlParameter("@SecOrder_ID", SecOrder_ID));
                SqlDataReader reader = cmd.ExecuteReader();
                while (reader.Read())
                {
                    M1Dal oM1 = new M1Dal();
                    oM1.SecOrder_ID = ToInt64(reader["SecOrder_ID"]);
                    oM1.Process_ID = ToInt64(reader["Process_ID"]);
                    oM1.Portfolio_Client_ID = ToString(reader["Portfolio_Client_ID"]);
                    oM1.Sec_Client_ID = ToString(reader["Sec_Client_ID"]);
                    oM1.Tran_Client_Open_ID = ToString(reader["Tran_Client_Open_ID"]);
                    oM1.Tran_Quantity = ToDecimal(reader["Tran_Quantity"]);
                    oM1.NewTran_Quantity = ToDecimal(reader["Tran_Quantity"]);
                    oM1.Remain_Quantity = ToDecimal(reader["Tran_Quantity"]);
                    oM1.Tran_Client_LongShort = ToString(reader["Tran_Client_LongShort"]);
                    oM1.WashSales_Exchange_Adjustment = ToDecimal(reader["WashSales_Exchange_Adjustment"]);
                    oM1.WashSales_Capital_Adjustment = ToDecimal(reader["WashSales_Capital_Adjustment"]);
                    //oM1.ModifiedWashSales_Exchange_Adjustment = ToString(reader["ModifiedWashSales_Exchange_Adjustment"]);
                    //oM1.ModifiedWashSales_Capital_Adjustment = ToString(reader["ModifiedWashSales_Capital_Adjustment"]);
                    oM1.WashSales_AssignedFrom_Portfolio_ID = ToString(reader["WashSales_AssignedFrom_Portfolio_ID"]);
                    oM1.WashSales_AssignedFrom_Open_ID = ToString(reader["WashSales_AssignedFrom_Open_ID"]);
                    oM1.WashSales_AssignedFrom_Close_ID = ToString(reader["WashSales_AssignedFrom_Close_ID"]);
                    oM1.WashSales_AssignedTo_Open_ID = ToString(reader["WashSales_AssignedTo_Open_ID"]);
                    oM1.WashSales_TackedDays = ToInt32(reader["WashSales_TackedDays"]);
                    oM1.WashSales_LossDate = ToDateTime(reader["WashSales_LossDate"]);
                    oM1.WashSales_Unique_From_ID = ToString(reader["WashSales_Unique_From_ID"]);
                    oM1.WashSales_Unique_To_ID = ToString(reader["WashSales_Unique_To_ID"]);
                    lst.Add(oM1);
                }
                reader.Close();
                reader = null;
            }
            finally
            {
                CloseConnection(cmd.Connection);
            }

            return lst;
        }
        public List<InProcessSecurityDal> GetSecurityInProcess(SqlInt64 SecOrder_ID)
        {
            List<InProcessSecurityDal> lst = new List<InProcessSecurityDal>();
            SqlCommand cmd = GetSPCommand("get_Securities_InProcessSecurities");
            try
            {
                cmd.Parameters.Add(new SqlParameter("@SecOrder_ID", SecOrder_ID));
                SqlDataReader reader = cmd.ExecuteReader();
                while (reader.Read())
                {
                    InProcessSecurityDal oSec = new InProcessSecurityDal();
                    oSec.Process_ID = ToInt64(reader["Process_ID"]);
                    oSec.SecOrder_ID = ToInt64(reader["SecOrder_ID"]);
                    oSec.Sec_Client_ID = ToString(reader["Sec_Client_ID"]);
                    oSec.SecGroup_ID = ToInt64(reader["SecGroup_ID"]);
                    lst.Add(oSec);
                }
                reader.Close();
                reader = null;
            }
            finally
            {
                CloseConnection(cmd.Connection);
            }

            return lst;
        }
        public List<SecMasterDal> GetSecuritySecMasters(SqlInt64 SecOrder_ID)
        {
            List<SecMasterDal> lst = new List<SecMasterDal>();
            SqlCommand cmd = GetSPCommand("get_Securities_SecurityMasters");
            try
            {
                cmd.Parameters.Add(new SqlParameter("@SecOrder_ID", SecOrder_ID));
                SqlDataReader reader = cmd.ExecuteReader();
                while (reader.Read())
                {
                    SecMasterDal oSecMast = new SecMasterDal();
                    oSecMast.SecOrder_ID = ToInt64(reader["SecOrder_ID"]);
                    oSecMast.Process_ID = ToInt64(reader["Process_ID"]);
                    oSecMast.Sec_Client_ID = ToString(reader["Sec_Client_ID"]);
                    //oSecMast.Sec_Client_Ticker = ToString(reader["Sec_Client_Ticker"]);
                    // oSecMast.Sec_Client_Cusip = ToString(reader["Sec_Client_Cusip"]);
                    //oSecMast.Sec_Client_Sedol = ToString(reader["Sec_Client_Sedol"]);
                    // oSecMast.Sec_Client_ISIN = ToString(reader["Sec_Client_ISIN"]);
                    // oSecMast.Sec_Client_Issue = ToString(reader["Sec_Client_Issue"]);
                    oSecMast.Sec_Client_Und_ID = ToString(reader["Sec_Client_Und_ID"]);
                    oSecMast.Sec_Client_Sim_ID = ToString(reader["Sec_Client_Sim_ID"]);
                    // oSecMast.Sec_Client_Sim_ID_Date = ToDecimal(reader["Sec_Client_Sim_ID_Date"]);
                    oSecMast.Sec_Client_Ident_ID = ToString(reader["Sec_Client_Ident_ID"]);

                    oSecMast.Sec_Client_Und_SharesContract = ToDecimal(reader["Sec_Client_Und_SharesContract"]);
                    oSecMast.Sec_Client_Sim_SharesContract = ToDecimal(reader["Sec_Client_Sim_SharesContract"]);
                    oSecMast.Sec_Client_Ident_SharesContract = ToDecimal(reader["Sec_Client_Ident_SharesContract"]);
                    lst.Add(oSecMast);
                }
                reader.Close();
                reader = null;
            }
            finally
            {
                CloseConnection(cmd.Connection);
            }

            return lst;
        }
        public List<TransactionsDal> GetSecurityTransactions(SqlInt64 SecOrder_ID)
        {
            List<TransactionsDal> lst = new List<TransactionsDal>();
            SqlCommand cmd = GetSPCommand("get_Securities_Transactions");
            try
            {
                cmd.Parameters.Add(new SqlParameter("@SecOrder_ID", SecOrder_ID));
                SqlDataReader reader = cmd.ExecuteReader();
                while (reader.Read())
                {
                    TransactionsDal otrans = new TransactionsDal();
                    otrans.SecOrder_ID = ToInt64(reader["SecOrder_ID"]);
                    otrans.Process_ID = ToInt64(reader["Process_ID"]);
                    otrans.Portfolio_Client_ID = ToString(reader["Portfolio_Client_ID"]);
                    otrans.Sec_Client_ID = ToString(reader["Sec_Client_ID"]);
                    //otrans.Tran_Option_ASP = ToString(reader["Tran_Option_ASP"]);
                    otrans.Tran_Client_Transaction_Code = ToString(reader["Tran_Client_Transaction_Code"]);
                    otrans.Tran_Client_Open_ID = ToString(reader["Tran_Client_Open_ID"]);
                    otrans.Tran_Open_Trade_Date = ToDateTime(reader["Tran_Open_Trade_Date"]);
                    //otrans.Tran_Open_Settle_Date = ToDateTime(reader["Tran_Open_Settle_Date"]);
                    otrans.Tran_Client_Close_ID = ToString(reader["Tran_Client_Close_ID"]);
                    otrans.Tran_Close_Trade_Date = ToDateTime(reader["Tran_Close_Trade_Date"]);
                    //otrans.Tran_Close_Settle_Date = ToDecimal(reader["Tran_Close_Settle_Date"]);
                    otrans.Tran_Client_LongShort = ToString(reader["Tran_Client_LongShort"]);
                    otrans.Tran_Quantity = ToDecimal(reader["Tran_Quantity"]);
                    otrans.NewTran_Quantity = ToDecimal(reader["Tran_Quantity"]);
                    otrans.Remain_Quantity = ToDecimal(reader["Tran_Quantity"]);
                    //otrans.Tran_Notional_Quantity = ToDecimal(reader["Tran_Notional_Quantity"]);
                    //otrans.Tran_ExpensesNotInBasis_Local = ToDecimal(reader["Tran_ExpensesNotInBasis_Local"]);
                    //otrans.Tran_ExpensesNotInBasis_Base = ToString(reader["Tran_ExpensesNotInBasis_Base"]);
                    //otrans.Tran_Notional_Cost_Local = ToString(reader["Tran_Notional_Cost_Local"]);
                    otrans.Tran_Orig_Cost_Base = ToDecimal(reader["Tran_Orig_Cost_Base"]);
                    otrans.Tran_Amort_Cost_Base = ToDecimal(reader["Tran_Amort_Cost_Base"]);
                    otrans.Tran_ProceedsMarket_Principle_Base = ToDecimal(reader["Tran_ProceedsMarket_Principle_Base"]);
                    otrans.Tran_GainLoss_Exchange = ToDecimal(reader["Tran_GainLoss_Exchange"]);
                    otrans.Tran_GainLoss_Capital = ToDecimal(reader["Tran_GainLoss_Capital"]);
                    otrans.Tran_GainLoss_Character = ToString(reader["Tran_GainLoss_Character"]);
                    otrans.Tran_FileType = ToString(reader["Tran_FileType"]);

                    lst.Add(otrans);
                }
                reader.Close();
                reader = null;
            }
            finally
            {
                CloseConnection(cmd.Connection);
            }

            return lst;
        }
        public SqlInt32 ReprocessSecurity(long ProcessID, long SecOrder_ID)
        {
            SqlInt32 iError = 0;
            SqlCommand cmd = GetSPCommand("set_Reprocess_Security");
            try
            {
                cmd.Parameters.Add(new SqlParameter("@Process_ID", ProcessID));
                cmd.Parameters.Add(new SqlParameter("@SecOrder_ID", SecOrder_ID));
                cmd.ExecuteNonQuery();
            }
            finally
            {
                CloseConnection(cmd.Connection);
            }
            return iError;
        }


    }
    public class CorpActionsDal
    {
        public Int64? SecOrder_ID { get; set; }
        public Int64? Process_ID { get; set; }
        public string Portifolio_Client_ID { get; set; }
        public string CorpAction_Sec_Client_ID { get; set; }
        public DateTime? CorpAction_Date { get; set; }
        public Int32? CorpAction_Type_ID { get; set; }
        public Decimal? CorpAction_RecievedShares { get; set; }
        public Decimal? CorpAction_DeliveredShares { get; set; }
        public string CorpAct_New_Sec_Client_ID { get; set; }
    }
    public class DividentsDal
    {
        public Int64? SecOrder_ID { get; set; }
        public Int64? Process_ID { get; set; }
        public string Portfolio_Client_ID { get; set; }
        public string Sec_Client_ID { get; set; }
        public string Div_Client_Dividend_ID { get; set; }
        public string Div_Client_Dividend_Code { get; set; }
        public string Div_Client_LongShort { get; set; }
        public Decimal? Div_Dividend_Gross_Local { get; set; }
        public Decimal? Div_Dividend_Gross { get; set; }
        public DateTime? Div_Dividend_Rate { get; set; }
        public DateTime? Div_TaxWithheld_Gross_Local { get; set; }
        public DateTime? Div_TaxWithheld_Gross { get; set; }
    }
    public class IdentifiedStraddlesDal
    {
        public Int64? SecOrder_ID { get; set; }
        public Int64? Process_ID { get; set; }
        public string Portfolio_Client_ID { get; set; }
        public string Sec_Client_ID { get; set; }
        public string Tran_Client_Open_ID { get; set; }
        public string Tran_Client_Close_ID { get; set; }
        public string Portfolio_Client_ID_Offset { get; set; }
        public string Sec_Client_ID_Offset { get; set; }
        public string Tran_Client_Open_ID_Offset { get; set; }
        public string Tran_Client_Close_ID_Offset { get; set; }
        public string IdentifiedStraddle_unique_ID { get; set; }
    }
    public class M1Dal
    {
        public Int64? SecOrder_ID { get; set; }
        public Int64? Process_ID { get; set; }
        public string Portfolio_Client_ID { get; set; }
        public string Sec_Client_ID { get; set; }
        public string Tran_Client_Open_ID { get; set; }
        public Decimal? Tran_Quantity { get; set; }
        public Decimal? NewTran_Quantity { get; set; }
        public Decimal? Remain_Quantity { get; set; }
        public string Tran_Client_LongShort { get; set; }
        public Decimal? WashSales_Exchange_Adjustment { get; set; }
        public Decimal? WashSales_Capital_Adjustment { get; set; }
        //public string WashSales_Exchange_Adjustment { get; set; }
        //public string WashSales_Capital_Adjustment { get; set; }
        public string WashSales_AssignedFrom_Portfolio_ID { get; set; }
        public string WashSales_AssignedFrom_Open_ID { get; set; }
        public string WashSales_AssignedFrom_Close_ID { get; set; }
        public string WashSales_AssignedTo_Open_ID { get; set; }
        public Int32? WashSales_TackedDays { get; set; }
        public DateTime? WashSales_LossDate { get; set; }
        public string WashSales_Unique_From_ID { get; set; }
        public string WashSales_Unique_To_ID { get; set; }
        public SecMasterDal SecMasterData { get; set; }
    }
    public class InProcessSecurityDal
    {
        public Int64? SecOrder_ID { get; set; }
        public Int64? Process_ID { get; set; }
        public string Sec_Client_ID { get; set; }
        public Int64? SecGroup_ID { get; set; }
    }
    public class SecMasterDal
    {
        public Int64? SecOrder_ID { get; set; }
        public Int64? Process_ID { get; set; }
        public string Sec_Client_ID { get; set; }
        public string Sec_Client_Ticker { get; set; }
        public string Sec_Client_Cusip { get; set; }
        public string Sec_Client_Sedol { get; set; }
        public string Sec_Client_ISIN { get; set; }
        public string Sec_Client_Issue { get; set; }
        public string Sec_Client_Und_ID { get; set; }
        public string Sec_Client_Sim_ID { get; set; }
        public Decimal? Sec_Client_Sim_ID_Date { get; set; }
        public string Sec_Client_Ident_ID { get; set; }

        public Decimal? Sec_Client_Und_SharesContract { get; set; }
        public Decimal? Sec_Client_Sim_SharesContract { get; set; }
        public Decimal? Sec_Client_Ident_SharesContract { get; set; }

    }
    public class TransactionsDal
    {
        public Int64? SecOrder_ID { get; set; }
        public Int64? Process_ID { get; set; }
        public string Portfolio_Client_ID { get; set; }
        public string Sec_Client_ID { get; set; }
        public string Tran_Option_ASP { get; set; }
        public string Tran_Client_Transaction_Code { get; set; }
        public string Tran_Client_Open_ID { get; set; }
        public DateTime? Tran_Open_Trade_Date { get; set; }
        public string Tran_Client_Close_ID { get; set; }
        public DateTime? Tran_Close_Trade_Date { get; set; }
        public string Tran_Client_LongShort { get; set; }
        public Decimal? Tran_Quantity { get; set; }
        public Decimal? NewTran_Quantity { get; set; }
        public Decimal? Remain_Quantity { get; set; }
        public Decimal? NewTran_QuantityDec
        {
            get
            {
                return Decimal.Round(NewTran_Quantity.Value, 4); 
            }
            
        }
        public Decimal? Remain_QuantityDec
        {
            get
            {
                return Decimal.Round(Remain_Quantity.Value, 4); ;
            }
           
        }
        //public Decimal Remain_Quantity { get; set; }
        public Decimal? Tran_Orig_Cost_Base { get; set; }
        public Decimal? Tran_Amort_Cost_Base { get; set; }
        public Decimal? Tran_ProceedsMarket_Principle_Base { get; set; }
        public Decimal? Tran_GainLoss_Exchange { get; set; }
        public Decimal? Tran_GainLoss_Capital { get; set; }
        public string Tran_GainLoss_Character { get; set; }
        public string Tran_FileType { get; set; }

        public bool IsM1Found { get; set; }
        public M1Dal M1Data { get; set; }
        public SecMasterDal SecMasterData { get; set; }
    }
    public enum SecurityType
    {
        ToProcess,
        InProcess,
        Processed,
        InQueue
    }
}
